#include "CameraActor.h"
#include "Scene.h"

namespace egg{

    CameraActor::CameraActor(){
        mSkyBox=0;
        mCamera=new Camera();
    }

    void CameraActor::addTo(Actor* _parent){
        Actor::addTo(_parent);
        getScene()->addCamera(mCamera);
    }

    void CameraActor::setSkyBox(TextureCubePtr _tex){
        if(mSkyBox==0){
            SkyBoxPass* pass0=new SkyBoxPass();
            MaterialPtr mtl(new Material());
            pass0->addTo(mtl);
            mSkyBox=new Drawable3D();
            mSkyBox->mPriority=DP_Background;
            mSkyBox->mMaterial=mtl;
        }
    }

    void CameraActor::onUpdateTransform(){
        TransformActor::onUpdateTransform();
        mCamera->setLocal2WorldMatrix(getLocal2WorldMatrix());
    }

    void CameraActor::onRendering(RenderContext& _context){
        if(mSkyBox){
            _context.addDrawable(mSkyBox);
        }
    }

}